package com.jshoperxms.components.wechat.pay;


import com.jshoperxms.components.wechat.WxConfig;

import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author WCS.Wang
 * @version V1.0
 * @Package com.hsz.redcross.controller.pay
 * @Name red-cross-plus
 * @Description: TODO 微信相关配置
 * @date 2018/7/10
 */
public class WXPayConfigImpl implements WXPayConfig {

    private static WXPayConfigImpl INSTANCE;

    public static WXPayConfigImpl getInstance() throws Exception {
        if (INSTANCE == null) {
            synchronized (WXPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }

    @Override
    public String getAppID() {
        return WxConfig.appid;
    }

    @Override
    public String getMchID() {
        return WxConfig.mchid;
    }

    @Override
    public String getKey() {
        return "langdunengshou123456langdunengsh";
    }

    @Override
    public InputStream getCertStream() {
        return null;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 6 * 1000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 8 * 1000;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return IWXPayDomainImpl.instance();
    }

    @Override
    public boolean shouldAutoReport() {
        return true;
    }

    @Override
    public int getReportWorkerNum() {
        return 6;
    }

    @Override
    public int getReportQueueMaxSize() {
        return 10000;
    }

    @Override
    public int getReportBatchSize() {
        return 10;
    }

    @Override
    public String getTradeType() {
        return "JSAPI";
    }

    @Override
    public String getNotifyUrl() {
        return WxConfig.NOTIFY_URL;
    }

    @Override
    public String getHostIP() {
        InetAddress addr;
        String ip = "";
        try {
            addr = InetAddress.getLocalHost();
            ip = addr.getHostAddress().toString(); //获取本机ip
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return ip;
    }

    @Override
    public String getSignType() {
        return "MD5";
    }
}
